function sendTask(time){
    // 异步任务
    taskPromise({timeout:time}).then((res) => {
        console.log('异步操作返回结果：' + res);
    })
}

function taskPromise(_option = {}) {
    return new Promise(resolve => {
      function task() {
        return new Promise((resolve, reject) => {
          // let _t = Math.ceil(Math.random() * 4) * 1000
          let _t = 2000
          setTimeout(function() {
            if (_option.timeout) {
              if (_t < _option.timeout) {
                resolve(true)
              } else {
                reject(false)
              }
            } else {
              resolve(true)
            }
          }, _t)
        })
      }
      task().then(() => {
        resolve(true)
      }).catch(() => {
        // 超时则抛出超时错误
        throw new Error('执行超时')
      })
    })
  }
  

